<template>
  <j-modal
    :title="'模板明细'"
    :width="width"
    :visible="visible" 
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
      <template slot="footer"> 
      <a-button  @click="handleCancel">关闭</a-button> 
    </template>

    <a-spin :spinning="confirmLoading">
      <j-form-container>
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
          <a-row>
            <a-col :span="24">
              <a-form-model-item label="数据源" :labelCol="labelCol" :wrapperCol="wrapperCol">
               {{model.dataSource=='dailyData'?'日报数据集':'实时数据集'}}
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol" >
                {{model.name}}
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="迭代次数" :labelCol="labelCol" :wrapperCol="wrapperCol" >
                {{model.iteration}}
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="序列长度" :labelCol="labelCol" :wrapperCol="wrapperCol">
                 {{model.seqLength}}
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="训练集比例" :labelCol="labelCol" :wrapperCol="wrapperCol">
                {{model.trainPercent}}
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="选择的特征列" :labelCol="labelCol" :wrapperCol="wrapperCol">
                {{model.selectedColumnsNames}}
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="预测列" :labelCol="labelCol" :wrapperCol="wrapperCol"  >
               {{model.predictColumnName}}
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
                {{model.remark}}
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
        <select-data-property-list-modal
          ref="selectDataPropertyList"
          @ok="selectDataPropertyOk"
          :selectType="selectType"
        />
      </j-form-container>
    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import JSelectDataSlot from '@/components/jeecgbiz/JSelectDataSlot2'
import SelectDataPropertyListModal from '@/views/corp/dataProperty/SelectDataPropertyList'
export default {
  name: 'BuildModal',
  components: {
    JSelectDataSlot,
    SelectDataPropertyListModal,
  },
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      selectType: '', 
      model: {
        name: '',
        remark: '',
        dataSource: 'dailyData', //数据源
        iteration: '', //迭代次数
        seqLength: '', //序列长度
        trainPercent: '', //训练集比例
        selectedColumns: '', //选择的特征列
        selectedColumnsNames:'',//
        predictColumn: '', //预测列
        predictColumnName: '',
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        dataSoltIds: [{ required: true, message: '请选择槽号!' }],
        startEndDate: [{ required: true, message: '请选择日期!' }],
        name: [
          { required: true, message: '请输入名称!' },
          { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' },
        ],
         iteration: [
          { required: true, message: '请输入迭代次数!' },
        ],
         seqLength: [
          { required: true, message: '请输入序列长度!' },
        ],
         trainPercent: [
          { required: true, message: '请输入训练集比例!' },
        ],
        selectedColumnsNames: [
          { required: true, message: '请选择特征列!' },
        ],
        predictColumnName: [
          { required: true, message: '请选择预测列!' },
        ],
      },
      url: {
        add: 'modelBase/template/add',
      },
    }
  },
  created() {
     
  },
  methods: {
    show(record) {
      debugger
      Object.assign(this.model, record)
      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
    },  
    handleCancel() {
      this.close()
    },
    doSelectDataPropertyList(type) {
      if (type == 1) {
        this.selectType = 'checkbox'
      }
      if (type == 2) {
        this.selectType = 'radio'
      }
      var propType = '日报'
      if(this.model.dataSource =='realTimeData'){
        propType = '实时'
      }
      this.$refs.selectDataPropertyList.show(propType)
    },
    selectDataPropertyOk(obj) {
      if (this.selectType == 'radio') {
        this.model.predictColumn = obj.propNo
        this.model.predictColumnName = obj.propName
      } else if (this.selectType == 'checkbox') {
          this.model.selectedColumns = obj.map(item=>item.propNo).join(',')
          this.model.selectedColumnsNames = obj.map(item=>item.propName) 
        }
    },
  },
}
</script>